<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('菜房入库列表')"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">

        <div class="col-sm-12 search-collapse">
            <div class="btn-group " style="margin: 0px auto;display: table;" role="group">
                <button type="button" class="top-link btn btn-sm btn-white">当天任务</button>
                <button type="button" class="top-link btn-sm btn-primary">入库</button>
                <button type="button" class="top-link btn-sm btn-white">仓储</button>
                <button type="button" class="top-link btn-sm btn-white">出库</button>
            </div>

            <div class="btn-group-sm" id="toolbar1" role="group">
                <h3 class="inline">检测蔬菜入库：</h3>

            </div>
        </div>


        <div class="col-sm-12 select-table table-striped ">
            <table id="bootstrap-table-1" data-mobile-responsive="true"></table>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <h3 class="inline">入库订单表：</h3>

            <a class="btn btn-primary" onclick="openOrder()">
                <i class="fa fa-table"></i> 入库记录单
            </a>
            <a class="btn btn-warning" onclick="confirmTable();">
                <i class="fa fa-send"></i> 确认
            </a>
            <!--<a class="btn btn-success disabled" onclick="$.operate.add()" shiro:hasPermission="system:ncInputCf:add">
                <i class="fa fa-plus"></i> 添加
            </a>-->
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table" data-mobile-responsive="true"></table>
        </div>
    </div>
</div>
<div th:include="include :: footer"></div>
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('system:ncInputCf:edit')}]];
    var removeFlag = [[${@permission.hasPermi('system:ncInputCf:remove')}]];
    var prefix = ctx + "system/ncInputCf";
    var cforderFor = [[${type}]];
    var cforderType = [[${@dict.getType('cforderType')}]];
    $(function () {
        /*待生成入库单的数据表*/
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            modalName: "菜房入库",
            queryParams: function queryParams(params) {
                var search = $.table.queryParams(params);
                search.params = {cforderFor: cforderFor};
                search.status = 1;
                return search;
            },

            showExport: true,
            showExport: false,
            showSearch: false,
            showRefresh: false,
            showColumns: false,
            showToggle: false,
            columns: [
                {
                    field: 'inputId',
                    title: '入库id',
                    visible: false
                },
                {
                    title: '序号',
                    formatter: function (value, row, index) {
                        return $.table.serialNumber(index);
                    }
                }, {
                    field: 'ncorderCf.cforderCode',
                    title: '订单编号',
                    formatter: function (value, row, index) {
                        if (row.ncorderCf.isCheck == '1') {
                            return '--'
                        } else {
                            return row.ncorderCf.cforderCode
                        }

                    }

                }, {

                    field: 'piciCode',
                    title: '蔬菜批次',
                },
                {
                    field: 'cropNameCn',
                    title: '作物名称',
                },
                {
                    field: 'cropVarietiesCn',
                    title: '作物品种',
                },
                {
                    field: 'teamCn',
                    title: '生产班组',

                },
                {
                    field: 'ncorderCf.cforderType',
                    title: '入库类型',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(cforderType, value);
                    }
                },
                {
                    field: 'inputAmout',
                    title: '入库数量（kg）',
                    sortable: true
                },
                {
                    field: 'inputTime',
                    title: '入库时间',
                    sortable: true
                },
                {
                    field: 'inputUser',
                    title: '入库经手人',
                    sortable: true
                },

                {
                    field: 'remark',
                    title: '备注',
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="inputEdit(\'' + row.inputId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="remove(\'' + row.inputId + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
        /*检测表格初始化结束*/
        initCheckTable();

        $('.top-link').click(function () {
            var index = $(this).index();
            switch (index) {
                case 0:
                    window.location.href = ctx + 'system/ncOrderCf/ncOrderCf-ordered?status=2&type=' + cforderFor;
                    return;
                case 1:
                    window.location.reload();
                    return;
                case 2:
                    window.location.href = ctx + 'system/ncInputCf/ncInputCf-stock?type=' + cforderFor;
                    return;
                case 3:
                    window.location.href = ctx + 'system/ncOuputCf?type=' + cforderFor;
                    return;
            }
        })
    });

    /*检测表格初始化*/
    function initCheckTable() {
        var prefix = ctx + "system/ncCheck";
        var datas = [[${@dict.getType('check_result')}]];
        var cforderType = [[${@dict.getType('cforderType')}]];
        /*检测表格初始化*/
        var options1 = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            modalName: "检测完成数据",
            showExport: false,
            showSearch: false,
            showRefresh: false,
            showColumns: false,
            showToggle: false,
            striped: true,
            id: 'bootstrap-table-1',
            //检测已确认生成订单的 并且订单的状态是待入库
            queryParams: function queryParams(params) {
                var search = $.table.queryParams(params);
                search.cforderStatus = 3;
                search.status = 2;
                search.params = {cforderFor: cforderFor};
                return search;
            },
            toolbar: 'toolbar1',
            columns: [
                {
                    field: 'checkId',
                    title: '检测id',
                    visible: false
                },
                {
                    title: '序号',
                    formatter: function (value, row, index) {
                        return $.table.serialNumber(index);
                    }
                }, {
                    field: 'ncorderCf.cforderCode',
                    title: '订单编号',
                    formatter: function (value, row, index) {
                        if (row.ncorderCf.isCheck == '1') {
                            return '--'
                        } else {
                            return row.ncorderCf.cforderCode
                        }

                    }

                },
                {
                    field: 'piciCode',
                    title: '蔬菜批次',
                    sortable: true
                },
                /*{
                    field: 'planCode',
                    title: '计划编号',
                    sortable: true
                },*/
                {
                    field: 'ncorderCf.cropNameCn',
                    title: '作物名称',
                },
                {
                    field: 'ncorderCf.cropVarietiesCn',
                    title: '作物品种',
                },
                {
                    field: 'teamCn',
                    title: '生产班组',
                    sortable: true

                },
                {
                    field: 'ncorderCf.cforderType',
                    title: '入库类型',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(cforderType, value);
                    }


                },

                {
                    field: 'yzl',
                    title: '抑制率(%)',
                    sortable: true
                },
                {
                    field: 'checkResult',
                    title: '检测结果',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(datas, value);
                    }
                },
                {
                    field: 'checkTime',
                    title: '检测时间',
                    sortable: true
                },
                {
                    field: 'checkUser',
                    title: '检测人员',
                    sortable: true
                },
                {
                    field: 'remark',
                    title: '备注',
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="confirmInput(\'' + row.checkId + '\')"><i class="fa fa-edit"></i>确认</a> ');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options1);
    }

    /*确认入库 单条*/
    function confirmInput(id) {
        var url = ctx + "system/ncCheck/confirmInput/" + id;
        $.modal.open("确认入库", url);
    }


    /*表单确认*/
    function confirmTable() {
        var confirmTable = prefix + "/confirmTable?caifangType=" + cforderFor;
        var data = $('#bootstrap-table').bootstrapTable('getData');
        if (data && data.length > 0) {

            $.modal.confirm("确认生成检测单吗？", function () {
                var ids = [];
                $(data).each(function (i, e) {
                    ids.push(e.inputId);
                });
                var ids_str = ids.join(",");
                myPost(confirmTable, {ids: ids_str},
                    function (data) {

                        if (data.code == 0) {
                            layer.msg("提交成功")
                        } else {
                            layer.msg(data.msg);
                        }
                        reload()
                    }, function (e) {
                        layer.msg("确认失败!");
                        reload()
                    })

            })
        } else {
            layer.msg("未发现数据!")
        }

    }

    /*打开检测记录单*/
    function openOrder() {
        var orderType = 5;
        if (cforderFor == 2) {
            orderType = 7;
        }
        var url = ctx + 'system/ncOrder?orderType=' + orderType;
        $.modal.openTab("检测记录单", url);
    }

    function reload() {
        $('#bootstrap-table').bootstrapTable('refresh', {
            silent: true
        });
        $('#bootstrap-table-1').bootstrapTable('refresh', {
            silent: true
        });
    }

    if (cforderFor == 1) {
        setTitle("蔬菜整理间1-入库", false)
    } else {
        setTitle("蔬菜整理间2-入库", false)
    }

    function inputEdit(inputId) {
        var url = ctx + 'system/ncInputCf/edit/' + inputId;
        $.modal.open("入库编辑", url);
    }

    function remove(inputId) {
        $.modal.confirm("确定删除该条信息吗？", function () {
            var url = ctx + 'system/ncInputCf/remove';
            var data = {"ids": inputId};
            $.operate.submit(url, "post", "json", data,function () {
                reload();
            });
        });
    }

</script>
</body>
</html>